package cn.edu.zut.cs.business;

import cn.edu.zut.cs.DAO.BookDAO;
import cn.edu.zut.cs.module.Book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SaleService {

    BookDAO bookDAO;

    @Autowired
    @Qualifier(value = "BookDAOImpl")
    public void setBookDAO(BookDAO bookDAO) {
        this.bookDAO = bookDAO;
    }

    public void insert(Book book) {
        bookDAO.insertBook(book);
    }

    public void onSale(float sale) {
        List<Book> bookList = bookDAO.queryAll();
        for (Book b : bookList) {
            b.setPrice(b.getPrice() * sale);
            bookDAO.modifyBook(b);
        }
    }
}
